package com.mt.controller;


import cn.hutool.core.collection.CollUtil;
import com.mt.constants.Result;
import com.mt.pojo.CinemaSeat;
import com.mt.service.CinemaSeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Wang
 * @since 2020-12-11
 */
@RestController
public class CinemaSeatController {
    @Autowired
    CinemaSeatService seatService;

    @GetMapping("/seat/{hallId}")
    public Result listSeatInfoByHallId(@RequestParam("currentPage")int currentPage,
                                       @RequestParam("pageSize")int pageSize,
                                       @PathVariable Integer hallId){
        Result<Object> result = new Result<>();
        result.success(seatService.listSeatByHallId(currentPage,pageSize,hallId));
        return result;
    }


    @PostMapping("/seat/modify")
    public Result modifySeatInfo(@RequestBody CinemaSeat seat){
        Result<Object> result = new Result<>();
        ArrayList<Integer> list = CollUtil.newArrayList();
        list.add(seat.getId());
        result.success(seatService.changeStatusMultipleSeats(list,seat.getStatus()));
        return result;
    }

    @PostMapping("/seat/delete")
    public Result deleteSeatInfo(@RequestBody CinemaSeat seat){
        Result<Object> result = new Result<>();
        result.success(seatService.deleteSeat(seat.getId()));
        return result;
    }
}
